import machine import time # Define the ADC pin adc = machine.ADC(0) while True: # Read the voltage across the resistor voltage = adc.read_u16() / 65535 * 3.3 # Calculate the resistance of the CdS sensor resistance = 10000 * (3.3 / voltage - 1) # Determine the ambient light levels based on the resistance value if resistance > 10000: print("Very dark", end=" \r") elif resistance > 5000: print("Dark", end=" \r") elif resistance > 2000: print("Dim", end=" \r") elif resistance > 1000: print("Normal", end=" \r") else: print("Bright", end=" \r") # Delay for a short period before reading the sensor again time.sleep(0.1)